package com.example.arve;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.net.Uri;
import android.os.Environment;
import android.util.Log;

/**
 * Description:
 * This class just handles basic file io. There are still a few classes that do file io without this, which is outside
 * of their responsibilities.
 * 
 * What's working:
 * 	- Everything!
 * What's not:
 *  - Nothing!
 * @author Richard
 *
 */
public class FileUri
{
	private static String FOLDER_NAME = "ARVE";
	
	/**
	 * Chances are this function will be killed off a little later;
	 * just using it at the moment to store the picture to make sure images are
	 * coming in fine.
	 * @return The image file that we built
	*/
	public static File createImageFile()
	{
		//If we actually have storage to use
		if(Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
		{
			//SDCard + Folder name
	        File dir = new File(Environment.getExternalStorageDirectory(), FOLDER_NAME);
	        if (!dir.exists()) //If the directory doesn't exist
	            if (!dir.mkdirs()) //If we weren't able to make the directory
	            {
	                Log.d("FileUri", "failed to create directory"); //Fail, fail, fail!
	                return null;
	            }
	       
	        //Just giving the file the time of day
	        String current_time = dateToString();
	        File picture_file = null;
	        //And make the file! Woo!
        	picture_file = new File(dir.getPath() + File.separator + "ARVE_" + current_time + ".jpg");

	        return picture_file;
		}
		return null;
	}
	
	/**
	 * Just grabs the current date and places it in a string format
	 * @return A string representation of the date
	 */
	public static String dateToString()
	{
		return new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
	}
	
	/**
	 * May kill this off as well; not sure yet
	 * @return The Uri of the file
	*/
	public static Uri getURI(File _data)
	{
		return Uri.fromFile(_data);
	}
}
